#include"host.h"

const char *ssid     = "IOTLab-419";           // wifi的ssid
const char *password = "87654321";      // wifi密码

HTTPClient httpclient;     //定义一个HTTPClient对象

//const char* city = "北京";    //查询天气的地址
//const char* apikey = "8019fe3a316a4bd29368ce779a62db7a";
const char* url = "http://api.jirengu.com/getWeather.php?city=郑州";   //定义url
//const char* url = "https://free-api.heweather.net/s6/weather/now?location=zhengzhou&key=8019fe3a316a4bd29368ce779a62db7a";   //定义url
String payload;
void setup() {
    Serial.begin(9600);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid,password);
    Serial.println();
    Serial.print("connect to ");
    Serial.println(WiFi.SSID());
    while(WiFi.status() != WL_CONNECTED){
        delay(500);
        Serial.print(".");
    }
    Serial.println();
    Serial.print(WiFi.SSID());
    Serial.println(" is connected.");
    delay(500);
   
}

void loop() {
    httpclient.begin(url);
    int code = httpclient.GET();
    if(code == HTTP_CODE_OK){
        Serial.print("code is ");
        Serial.println(code);
        Serial.println("httpclient is connected.");
        payload = httpclient.getString();
        Serial.print("payload : ");
        Serial.println(payload);
    }
    else{
        Serial.print("code is ");
        Serial.println(code);
        Serial.println("httpclient isn't connected.");
    }
    httpclient.end();
    delay(5000);
}
